<template>
  <div class="search">
    <label>
      <span>选择部门</span>
      <el-select v-model="$store.state.roleManage.userSearchDTO.departId" clearable>
        <el-option v-for="item in departList" :key="item.id" :value="item.id" :label="item.name"></el-option>
      </el-select>
    </label>
    <label>
      <span>帐号状态</span>
      <el-select v-model="$store.state.roleManage.userSearchDTO.status" clearable>
        <el-option v-for="item in statusList" :key="item.code" :value="item.code" :label="item.name"></el-option>
      </el-select>
    </label>
    <label>
      <span>用户名称</span>
      <el-input placeholder="请输入" v-model="$store.state.roleManage.userSearchDTO.name" clearable></el-input>
    </label>
    <a href="javascript:void(0);" class="find" @click="getUserList">查询</a>
    <a href="javascript:void(0);" class="reset" @click="reset">重置</a>
  </div>
</template>

<script>
import { getDepartList } from '@/api/roleManage'
import { resetObj } from '@/utils/resetObj'
export default {
  data () {
    return {
      departSearchDTO: {
        index: 1,
        pageSize: 1000,
        name: ''
      },
      departList: [],
      statusList: [
        {
          code: 1,
          name: '启用'
        },
        {
          code: 0,
          name: '禁用'
        }
      ]
    }
  },
  methods: {
    // 获取部门下拉列表
    getDepartList () {
      getDepartList().then(res => {
        this.departList = res.data.data
      })
    },
    // 获取用户列表
    getUserList () {
      this.$store.dispatch('roleManage/getUserList')
    },
    // 重置查询条件
    reset () {
      resetObj(this.$store.state.roleManage.userSearchDTO)
      this.$store.commit('roleManage/set_userSearchDTO_index', 1)
      this.$store.commit('roleManage/set_userSearchDTO_pageSize', 10)
      this.getUserList()
    }
  },
  created () {
    this.getDepartList()
    this.getUserList()
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-input__inner {
  height: 40px;
}

::v-deep .el-range-separator {
  width: 10%;
}

::v-deep .el-select-dropdown {
  top: 40px!important;
}

::v-deep .el-select-dropdown__empty {
  top: 40px!important;
}

.search {
  width: 100%;
  background-color: #fff;
  border-radius: 5px;
  padding-left: 30px;
  padding-top: 24px;
  label {
    margin-right: 58px;
    display: inline-block;
    margin-bottom: 20px;
    span {
      font-size: 14px;
      color: #666;
      margin-right: 12px;
    }

    .el-select {
      width: 240px;
    }

    .el-input {
      width: 240px;
    }
  }

  .find, .reset {
    width: 84px;
    height: 36px;
    border-radius: 18px;
    font-size: 14px;
    display: inline-block;
    text-align: center;
    line-height: 36px;
    margin-bottom: 20px;
  }

  .find {
    background-color: #4868FF;
    margin-right: 16px;
  }

  .reset {
    border: 1px solid #4868FF;
    color: #4868FF;
  }
}
</style>
